package edu.nf.project.services.storeOperation.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.nf.project.entitys.dto.storeOperation.RefundDTO;
import edu.nf.project.entitys.entity.storeOperation.convention.operate.RefundImage;
import edu.nf.project.entitys.entity.storeOperation.convention.operate.RefundRequest;
import edu.nf.project.mappers.storeOperation.convention.RefundDTOMapper;
import edu.nf.project.services.storeOperation.RefundDTOService;
import edu.nf.project.services.storeOperation.RefundImageService;
import edu.nf.project.services.storeOperation.RefundRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CSY
 * @date 2025 - 06 - 20
 */
@Service
public class RefundDTOServiceImpl implements RefundDTOService {
    @Autowired
    private RefundImageService refundImageService;

    @Autowired
    private RefundDTOMapper refundDTOMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveRefundDTO(MultipartFile file, String refundImageJson) {
        try {
            //解析JSON字符串为对象
            ObjectMapper objectMapper = new ObjectMapper();
            RefundImage refundImage = objectMapper.readValue(refundImageJson, RefundImage.class);
            //添加并上传
            refundImageService.insertRefundImage(file,refundImage);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public RefundDTO getRefundDTOByRefundId(Integer rrId) {
        RefundDTO refundDTO = refundDTOMapper.selectRefundDTOByRrId(rrId);
        return refundDTO;
    }

    @Override
    public List<RefundDTO> listRefundDTO() {
        return refundDTOMapper.listRefundDTO();
    }
}
